<script setup >
import {h, onMounted, ref} from "vue";
import axios from "axios";
import {ElNotification} from "element-plus";
const fullscreenLoading = ref(false)
const form=ref({
  id:'',
  username:'',
  nickname:'',
  email:''
})
const getall=()=>{
  axios.get("/user/userInfo").then(result=>{
    form.value.id=result.data.data.id
    form.value.username=result.data.data.username
    form.value.nickname=result.data.data.nickname
    form.value.email=result.data.data.email

  }).catch(err=>{
    return   ElNotification({
      title: '消息',
      message: h('i', { style: 'color: teal' },'用户数据载入失败'),
    })
  })
}
const update=()=>{

axios.put("/user/update", form.value).then(result=>{
  if (result.data.code==0){
    fullscreenLoading.value = true
    setTimeout(() => {
      localStorage.clear();
      fullscreenLoading.value = false
    }, 2800)
    return   ElNotification({
      title: '消息',
      message: h('i', { style: 'color: teal' },"更新成功"),
    })
  }

}).catch(err=>{
  return   ElNotification({
    title: '消息',
    message: h('i', { style: 'color: teal' },"更新失败"),
  })
})
}
onMounted(()=>{
getall()

})
</script>

<template>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="用户名">
      <el-input v-model="form.username" />
    </el-form-item>
    <el-form-item label="昵称">
      <el-input v-model="form.nickname" />
    </el-form-item>
    <el-form-item label="email">
      <el-input v-model="form.email" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="update" v-loading.fullscreen.lock="fullscreenLoading">更新</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped>

</style>